<?php
$isReloadable = true;
require_once("../../pers/inc.config.php");
require_once(R2_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(R2_FS_WEB_ROOT.'/app/_inc/funct.html.php');

//Gestione azioni
if (reqvar('azione')=='elimina'){$msgPag .= confEli();}

// Dati: commessa selezionata
$sqlSel = " SELECT c.* FROM cliente c WHERE c.id_cliente = ".intval(reqVar('id'));
$objDB->query($sqlSel,'selRec');
if (!$acRec = $objDB->fetch('selRec')) {
	backOnErr("var. id. '".reqVar('id')."' mancante o errato");
}

$sCmdL = "";
$sCmdR = "";

if ($objSess->abilitaz['gescomm'] == 'W') {
	$sCmdR .= "<a class='cmd1' href='cliMod.php?id=".reqVar('id')."&xsn=".XSN."' >modifica</a>";
	$sCmdR .= "&nbsp;&nbsp;&nbsp";
	$sCmdR .= "<a class='cmd1' href='javascript:confElim();' >elimina</a>";
}	
$sCmdR .= cmdTorna('torna');

$aMenuPag = array();
include("_inc/inc.aMenuPag.php");
testaHtml('Visualizza Cliente', $msgPag, '30.10.10', $aMenuPag);
?>
<script type="text/javascript">
<!--
function confElim() {
	if (confirm("Confermi l'eliminazione ?")) {
		document.location.href = "cliView.php?id=<?=reqVar('id')?>&azione=elimina&xsn=<?=XSN?>";
	}
}
//-->
</script>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='top'><?=$sCmdL?></td>
      <td class="cmd1" align="right"><?=$sCmdR?></td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
<?php echo getHtmlRigaRif();?>
	<tr>
		<td class="tit1" colspan='20' align='center'>Cliente</td>
	</tr>
    <tr>
   	<td class="lab1" colspan='1'>Id.</td>
	  	<td class="txt1" colspan='1'><?=$acRec['id_cliente'];?></td>
   	<td class="lab1" colspan='2'>Denominazione</td>
	  	<td class="txt1" colspan='13'><?=$acRec['denominaz'];?></td>
   	<td class="lab1" colspan='2'>Sospeso</td>
	  	<td class="txt1" colspan='1'><?=$acRec['sospeso'];?></td>
    </tr>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='top'><?=$sCmdL?></td>
      <td class="cmd1" align="right"><?=$sCmdR?></td>
   </tr>
</table>
<?
codaHtml();
exit();

function confEli() {
	global $objDB, $objSess;

	$msg = '';
	
	// verifico l' esistenza di cliente su rint, commessa e clienti_comm
	$sSql = " SELECT id_cliente FROM rint WHERE id_cliente = ".reqVarInt('id');
	$objDB->query($sSql);
	$acRint = $objDB->fetch();	
	if ($acRint) {
		$msg .= 'eliminazione non consentita:<br>esistono rint <br>';
	}
	$sSql = " SELECT id_cliente FROM commessa WHERE id_cliente = ".reqVarInt('id');
	$objDB->query($sSql);
	$acRint = $objDB->fetch();	
	if ($acRint) {
		$msg .= 'eliminazione non consentita:<br>esistono commesse <br>';
	}
	$sSql = " SELECT id_cliente FROM clienti_comm WHERE id_cliente = ".reqVarInt('id');
	$objDB->query($sSql);
	$acRint = $objDB->fetch();	
	if ($acRint) {
		$msg .= 'eliminazione non consentita:<br>esistono clienti_comm <br>';
	}
	if ($msg != '') {return $msg;}
	
	$sSql = "DELETE FROM cliente WHERE id_cliente = ".reqVarInt('id');
	$objDB->query($sSql);
	header("Location: ".urlTorna());
	exit();
}

?>